//
//  MyPopoverWindowController.m
//  sandbox
//
//  Created by 杨岑 on 1/7/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "MyPopoverWindowController.h"

@interface MyPopoverWindowController ()
@property (weak) IBOutlet NSButton* templateButton;
@end

@implementation MyPopoverWindowController

- (CGFloat)handleWidth
{
    return self.templateButton.bounds.size.height;
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {

    }
    return self;
}

- (void)windowDidLoad {
    [super windowDidLoad];
    
    self.window.styleMask = NSBorderlessWindowMask;
    self.window.movableByWindowBackground = self.properties.movableByBackground;
    self.window.level = NSNormalWindowLevel;
    self.window.opaque = self.properties.opaque;
    self.window.alphaValue = self.properties.alphaValue;
    self.window.backgroundColor = [NSColor clearColor];
}

- (void)windowDidResignKey:(NSNotification *)notification
{
    NSDictionary* fadeOutProps = @{NSViewAnimationTargetKey: self.window, NSViewAnimationEffectKey: NSViewAnimationFadeOutEffect};
    NSViewAnimation* anim = [[NSViewAnimation alloc] initWithViewAnimations:@[fadeOutProps]];
    anim.duration = .2;
    anim.animationBlockingMode = NSAnimationBlocking;
    anim.animationCurve = NSAnimationEaseOut;
    [anim startAnimation];
}

@end
